//
//  CMDBCacheDataManager.swift
//  CMDB
//
//  Created by 王磊 on 17/4/5.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit
private let CMDBCacheDataName: String = "CMDB"
class CMDBCacheDataManager: NSObject {
    
    static let getInstance: CMDBCacheDataManager = CMDBCacheDataManager()
    
    private override init() {
        super.init()
        
    }
    private var cache: YYCache = YYCache(name: CMDBCacheDataName)!
}
// MARK: 数据 存取
extension CMDBCacheDataManager: CMDBCacheDataManagerDelegate {
    
    // 存取字典
    internal func saveDictionary(json: NSDictionary? ,identifier: String?) {
        if let identifier = identifier , json = json {
            
            cache.setObject(json, forKey: identifier)
        }
    }
    internal func queryData(identifier: String?) -> Dictionary<String,AnyObject>? {
        guard let identifier = identifier else {
            
            return nil
        }
        return cache.objectForKey(identifier) as? Dictionary<String,AnyObject>
    }
    
    // 存取 数组
    internal func saveArray(array: NSArray? ,identifier: String?) {
        if let identifier = identifier , array = array {
            
            cache.setObject(array, forKey: identifier)
        }
    }
    internal func queryArray(identifier: String?) -> NSArray? {
        guard let identifier = identifier else {
            
            return nil
        }
        return cache.objectForKey(identifier) as? NSArray
    }
}